package main

import (
	"encoding/json"
	"fmt"
)

type Student struct {
	ID     int
	Gender string
	Name   string
}

type Class struct {
	Title   string
	Student []Student
}

func main() {
	//c1 := Class{
	//	Title: "一班",
	//	Student: []Student{
	//		{
	//			ID:     1,
	//			Gender: "男",
	//			Name:   "李四",
	//		},
	//		{
	//			ID:     2,
	//			Gender: "女",
	//			Name:   "王丽",
	//		},
	//	},
	//}

	//fmt.Printf("%#v\n", c1) //main.Class{Title:"一班", Student:[]main.Student{main.Student{ID:1, Gender:"男", Name:"李四"}, main.Student{ID:2, Gender:"女", Name:"王丽"}}}

	c2 := Class{
		Title:   "二班",
		Student: make([]Student, 0),
	}

	for i := 1; i < 10; i++ {
		s := Student{
			ID:     i,
			Name:   fmt.Sprintf("stu_%v", i),
			Gender: "男",
		}
		c2.Student = append(c2.Student, s)
	}

	//fmt.Printf("%#v\n", c2)
	strByte, err := json.Marshal(c2)
	if err != nil {
		panic(err)
	}
	str := string(strByte)
	fmt.Println(str) //{"Title":"二班","Student":[{"ID":1,"Gender":"男","Name":"stu_1"},{"ID":2,"Gender":"男","Name":"stu_2"},{"ID":3,"Gender":"男","Name":"stu_3"},{"ID":4der":"男","Name":"stu_4"},{"ID":5,"Gender":"男","Name":"stu_5"},{"ID":6,"Gender":"男","Name":"stu_6"},{"ID":7,"Gender":"男","Name":"stu_7"},{"ID":8,der":"男","Name":"stu_8"},{"ID":9,"Gender":"男","Name":"stu_9"}]}
}
